package com.gome.ocean.service.gddl.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.gome.ocean.common.exception.AppServiceException;
import com.gome.ocean.dao.gddl.AppDAO;
import com.gome.ocean.dao.model.gddl.AppBO;
import com.gome.ocean.service.gddl.AppService;

@Service("appService")
@Transactional("transactionManager")
public class AppServiceImpl implements AppService {

    private static final Logger LOG = LoggerFactory.getLogger(AppServiceImpl.class);

    @Resource(name = "appDAO")
    private AppDAO              appDao;

    @Override
    public boolean insertAppBO(AppBO appBO) {
        return appDao.insertAppBO(appBO) > 0;
    }

    @Override
    public boolean removeAppBOById(Long id) {
        return appDao.removeAppBOById(id) > 0;
    }

    @Override
    public boolean updateAppBO(AppBO appBO) {
        return appDao.updateAppBO(appBO) > 0;
    }

    @Override
    public AppBO findAppBOById(Long id) {
        return appDao.findAppBOById(id);
    }

    @Override
    public Page<AppBO> findAllApps(int pageNum, int pageSize) {
        return (Page) appDao.findAllApps(new RowBounds(pageNum, pageSize));
    }

    @Override
    public Page<AppBO> findAllAppsByProjectNames(int pageNum, int pageSize, List<String> projectNames)
                                                                                                      throws AppServiceException {
        Page<AppBO> appBOs = null;
        try {
            appBOs = (Page) appDao.findAllAppsByProjectNames(projectNames, new RowBounds(pageNum, pageSize));
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            throw new AppServiceException(e.getMessage());
        }
        return appBOs;
    }

    @Override
    public List<AppBO> findAllApps() {
        return appDao.findAllApps();
    }

    @Override
    public AppBO findAppBOByAppName(String appName) {
        return appDao.findAppBOByAppName(appName);
    }

	@Override
	public List<AppBO> findAppBOsByAppName(String appName) {
		return appDao.findAppBOsByAppName(appName);
	}

}
